home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Graphics Containers / The State of a Graphics Object / Clipping Region / GDITEST70.dpr
Encoding:
Text File  |  2003-10-15  |  2.7 KB  |  107 lines

  1. program GDITEST70;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   Pen: TGPPen;
  14.   brush: TGPSolidBrush;
  15.   Region: TGPRegion;
  16. begin
  17.   graphics := TGPGraphics.Create(DC);
  18.  
  19.   Pen := TGPPen.Create(MakeColor(255, 255, 0, 0), 5);  // opaque red, width 5
  20.   brush := TGPSolidBrush.Create(MakeColor(255, 180, 255, 255));  // opaque aqua
  21.  
  22.   // Create a plus-shaped region by forming the union of two rectangles.
  23.   Region := TGPRegion.Create(MakeRect(50, 0, 50, 150));
  24.   region.Union(MakeRect(0, 50, 150, 50));
  25.   graphics.FillRegion(brush, region);
  26.  
  27.   // Set the clipping region.
  28.   graphics.SetClip(region);
  29.  
  30.   // Draw two clipped lines.
  31.   graphics.DrawLine(pen, 0, 30, 150, 160);
  32.   graphics.DrawLine(pen, 40, 20, 190, 150);
  33.  
  34.  
  35.   brush.Free;
  36.   Region.Free;
  37.   Pen.Free;
  38.   graphics.Free;
  39. end;
  40.  
  41.  
  42. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  43. var
  44.   Handle: HDC;
  45.   ps: PAINTSTRUCT;
  46. begin
  47.   case message of
  48.     WM_PAINT:
  49.       begin
  50.         Handle := BeginPaint(Wnd, ps);
  51.         OnPaint(Handle);
  52.         EndPaint(Wnd, ps);
  53.         result := 0;
  54.       end;
  55.  
  56.     WM_DESTROY:
  57.       begin
  58.         PostQuitMessage(0);
  59.         result := 0;
  60.       end;
  61.  
  62.    else
  63.       result := DefWindowProc(Wnd, message, wParam, lParam);
  64.    end;
  65. end;
  66.  
  67. var
  68.   hWnd     : THandle;
  69.   Msg      : TMsg;
  70.   wndClass : TWndClass;
  71. begin
  72.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  73.    wndClass.lpfnWndProc    := @WndProc;
  74.    wndClass.cbClsExtra     := 0;
  75.    wndClass.cbWndExtra     := 0;
  76.    wndClass.hInstance      := hInstance;
  77.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  78.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  79.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  80.    wndClass.lpszMenuName   := nil;
  81.    wndClass.lpszClassName  := 'GettingStarted';
  82.  
  83.    RegisterClass(wndClass);
  84.  
  85.    hWnd := CreateWindow(
  86.       'GettingStarted',       // window class name
  87.       'Clipping Region',      // window caption
  88.       WS_OVERLAPPEDWINDOW,    // window style
  89.       Integer(CW_USEDEFAULT), // initial x position
  90.       Integer(CW_USEDEFAULT), // initial y position
  91.       Integer(CW_USEDEFAULT), // initial x size
  92.       Integer(CW_USEDEFAULT), // initial y size
  93.       0,                      // parent window handle
  94.       0,                      // window menu handle
  95.       hInstance,              // program instance handle
  96.       nil);                   // creation parameters
  97.  
  98.    ShowWindow(hWnd, SW_SHOW);
  99.    UpdateWindow(hWnd);
  100.  
  101.    while(GetMessage(msg, 0, 0, 0)) do
  102.    begin
  103.       TranslateMessage(msg);
  104.       DispatchMessage(msg);
  105.    end;
  106. end.
  107.